﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace DownloadBook {
    /// <summary>
    /// 小说实体类
    /// </summary>
    public class Book : IComparable<Book>{
        /// <summary>
        /// 书名
        /// </summary>
        public string name;

        /// <summary>
        /// 网址
        /// </summary>
        public string url;

        /// <summary>
        /// 作者
        /// </summary>
        public string author;

        /// <summary>
        /// 简介
        /// </summary>
        public string introduction;

        /// <summary>
        /// 是否忽略标题
        /// </summary>
        public bool ignoreContentTitle;

        /// <summary>
        /// html文件夹
        /// </summary>
        [JsonIgnore]
        public string htmlDirectory;

        /// <summary>
        /// 章节列表
        /// </summary>
        [JsonIgnore]
        public List<Content> contentList;



        public override string ToString(){
            StringBuilder sb = new StringBuilder();
            if(!string.IsNullOrEmpty(name)){
                sb.Append(name);
            }
            if(!string.IsNullOrEmpty(author)){
                if(sb.Length > 0){
                    sb.Append(" - ");
                }
                sb.Append(author);
            }
            return sb.ToString();
        }

        /// <summary>
        /// 载入基础信息
        /// </summary>
        /// <param name="book"></param>
        public void LoadBasic(Book book) {
            if (book != null) {
                this.name = book.name;
                this.url = book.url;
                this.author = book.author;
                this.introduction = book.introduction;
                this.htmlDirectory = book.htmlDirectory;
                this.ignoreContentTitle = book.ignoreContentTitle;
            }
        }
        public int CompareTo(Book other) {
            string name = this.name;
            if (string.IsNullOrEmpty(name)) {
                return 1;
            } else if (string.IsNullOrEmpty(other.name)) {
                return -1;
            } else {
                return name.CompareTo(other.name);
            }
        }
    }
}
